package com.feng.boot.jdbc.spring;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

import javax.sql.DataSource;

/**
 * @author Lee
 */
//@Component
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof DataSource) {
            System.out.println("postProcessBeforeInitialization->" + beanName + ": " + bean);
        } else {
            System.out.println("-------------postProcessBeforeInitialization----------not is datasource-----------------------");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof DataSource) {
            System.out.println("postProcessAfterInitialization->" + beanName + ": " + bean);
        } else {
            System.out.println("-------------postProcessAfterInitialization----------not is datasource-----------------------");
        }
        return bean;
    }
}
